
package com.jihox.abookpro.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.EditText;

import com.jihox.abookpro.R;

@SuppressLint({ "DrawAllocation" })
public class BorderEditText extends EditText{

	private boolean closure;
	public BorderEditText(Context context) {
		super(context);
	}
	public BorderEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(attrs);
	}
	public void init(AttributeSet attrs){  
		TypedArray t = getContext().obtainStyledAttributes(attrs,R.styleable.BorderTextView);  
		closure = t.getBoolean(R.styleable.BorderTextView_closure, true);  
		t.recycle();
	}  
	private int sroke_width = 1;
	@Override
	protected void onDraw(Canvas canvas) {
		Paint paint = new Paint();
		//  将边框设为黑色
		paint.setColor(android.graphics.Color.LTGRAY);
		//  画TextView的4个边
		canvas.drawLine(0, 0, this.getWidth() - sroke_width+1, 0, paint);
		canvas.drawLine(0, 0, 0, this.getHeight() - sroke_width, paint);
		if(closure){
			canvas.drawLine(this.getWidth() - sroke_width, 0, this.getWidth() - sroke_width, this.getHeight() - sroke_width, paint);
		}
		canvas.drawLine(0, this.getHeight() - sroke_width, this.getWidth() - sroke_width+1, this.getHeight() - sroke_width, paint);
		super.onDraw(canvas);
	}
}
